<template>
  <div class="user-container">
    <!-- 用户个人资料 -->
    <div class="user-profile">
      <div class="info">
        <van-image round :src="userInfo.photo" />
        <h3 class="name">
          {{userInfo.name}}
          <br />
          <van-tag size="mini">申请认证</van-tag>
        </h3>
      </div>
      <van-row>
        <van-col span="8">
          <p>{{userInfo.art_count}}</p>
          <p>动态</p>
        </van-col>
        <van-col span="8">
          <p>{{userInfo.follow_count}}</p>
          <p>关注</p>
        </van-col>
        <van-col span="8">
          <p>{{userInfo.fans_count}}</p>
          <p>粉丝</p>
        </van-col>
      </van-row>
    </div>
    <!-- 编辑入口 -->
    <van-cell-group class="user-group">
      <van-cell icon="edit" title="编辑资料" to="/editUser" is-link />
      <van-cell icon="chat-o" title="小智同学" to="/chatMachion" is-link />
      <van-cell icon="warning-o" title="退出登录"  is-link @click="logout" />
    </van-cell-group>
  </div>
</template>

<script>
import { getUserInfo } from '@/api/user.js'
// 引入接口
export default {
  name: 'UserIndex',
  data () {
    return {
      userInfo: {}
    }
  },
  methods: {
    logout () {
      this.$dialog.confirm({
        title: '温馨提示',
        message: '确定要退出登录么'
      }).then(() => {
        console.log(11)
        // on confirm
        // 清除token vues&ls
        this.$store.commit('clearToken')
        // 返回登录页面
        this.$router.push('/login')
      })
        .catch(() => {
          // on cancel
          console.log(22)
        })
    },

    async hgetUserInfo () {
      const res = await getUserInfo()
      console.log(res)
      this.userInfo = res.data.data
      this.$store.commit('setUserInfo', res.data.data)
    }
  },
  mounted () {
    this.hgetUserInfo()
  }
}
</script>

<style lang="less" scoped>
.user-container{
  position: fixed;
  top:0;
  bottom: 0;
  width: 100%;
}
.user {
  &-profile {
    width: 100%;
    height: 200px;
    display: block;
    background: #3296fa;
    color: #fff;
    .info {
      display: flex;
      padding: 20px;
      align-items: center;
      .van-image {
        width: 64px;
        height: 64px;
      }
      .name {
        font-size: 16px;
        font-weight: normal;
        margin-left: 10px;
      }
      .van-tag {
        background: #fff;
        color: #3296fa;
      }
    }
    p {
      margin: 0;
      text-align: center;
    }
  }
  &-group {
    margin-bottom: 15px;
  }
  &-links {
    padding: 15px 0;
    font-size: 12px;
    text-align: center;
    background-color: #fff;
    .van-icon {
      display: block;
      font-size: 24px;
      padding-bottom: 5px;
    }
  }
}
</style>
